from common.Base import Base, open_op_browser

login_url = "http://localhost:8080/ecshop/user.php"
path = r"C:\Users\GrapeLier\AppData\Roaming\Mozilla\Firefox\Profiles\iybiyjzp.default-release"


class MyOrderPage(Base):
    my_order_loc = ("link text", "我的订单")
    order_num_loc = ("css selector", "a[class='f6']")
    order_time_loc = ("css selector","tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2)")
    order_money_loc = ("css selector","tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(3)")
    order_status_loc = ("css selector","tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(4)")
    cancel_order_loc = ("link text", "取消订单")
    bought_again_loc = ("link text", "再次购买")

    def my_order(self):
        """
        定位我的订单
        :return:
        """
        self.click(self.my_order_loc)

    def get_order_text(self):
        """
        获取订单编号
        :return:
        """
        return self.get_element_text(self.order_num_loc)
    def get_time_text(self):
        """
        获取下单时间
        :return:
        """
        return self.get_element_text(self.order_time_loc)

    def get_money_text(self):
        """
        获取订单总金额
        :return:
        """
        return self.get_element_text(self.order_money_loc)

    def get_status_text(self):
        """
        获取订单状态
        :return:
        """
        return self.get_element_text(self.order_status_loc)
    def order_num(self, order_num):
        """
        定位订单编号,
        :return:
        """
        self.click(self.order_num_loc, order_num)

    def cancel_order(self):
        """
        定位取消订单按钮
        :return:
        """
        self.click(self.cancel_order_loc)

    def bought_again(self):
        """
        定位再次购买按钮
        :return:
        """
        self.click(self.bought_again_loc)


if __name__ == '__main__':
    # 打开浏览器
    driver = open_op_browser(path)
    mop = MyOrderPage(driver)
    # 打开网页
    mop.open_url(login_url)
    # 点击收货地址进入收货地址页面
    mop.my_order()
    # 获取订单编号
    print(mop.get_order_text())
    # 获取订单时间
    print(mop.get_time_text())
    # 获取订单总金额
    print(mop.get_money_text())
    # 获取订单状态
    print(mop.get_status_text())
    # 点击取消订单
    # mop.cancel_order()
    # 点击再次购买按钮
    # mop.bought_again()
